#Indicator
'**************************************************************
'*   Standard RSI Indicator  (StdRSI.txt)
'*     by Jeremy Williams
'*	   Dec. 10, 2007
'*
'*	Adapted from Technical Analysis of Stocks and Commodities
'*     April 2008
'*
'*  Summary: 
'*
'*      This indicator shows the inner workings of the standard RSI 
'*  indicator. By default, Omnitrader uses a slightly modified RSI 
'*  calculation. For this reason, the StdRSI indicator should be used
'*  when using the RSI Bands from the April 2008 issue of Technical 
'*  Analysis of Stocks and Commodities.
'*
'*  Parameters:
'*
'*  Period -  Specifies the number of periods used in the RSI calculation 
'*
'************************************************************** 

#Param "Period",14

Dim Diff	As Single
Dim Gain	As Single
Dim Loss	As Single
Dim N		As Single
Dim P		As Single
Dim myRS	As Single
Dim myRSI	As Single

' Calculate the gains and losses
Diff = C - C[1]
Gain = IIF( Diff > 0 , Diff, 0)
Loss = IIF (Diff < 0 , 0 - Diff, 0)

' Calculate the averages
N = (N[1]*(Period-1) + Gain ) / Period
P = (P[1]*(Period-1) + Loss ) / Period

' Calculate the RSI
myRS = N/P
myRSI = 100 - 100/(1+myRS)

' Plot the RSI
SetScales(0,100)
Plot("RSI",myRSI)
PlotLabel(30)
PlotLabel(70)

' Return the value calculated by the indicator
Return myRSI